package org.alino.core.utils;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.core.io.support.ResourcePatternResolver;

import java.io.IOException;
import java.util.Properties;

/**
 * @Desc TODO
 * @Author by Brant
 * @Date 2017/2/7
 */
public class PropUtils {
    public static Properties props =null;
    public static ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
    public final static String getString(String key){
        if(props == null){
            try {
                Resource[] resources = (Resource[]) resolver.getResources("classpath*:config*.properties");
                props = new Properties();
                for (Resource resource : resources) {
                    PropertiesLoaderUtils.fillProperties(props, resource);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return (null != props)?props.getProperty(key):null;
    }

    public static int getInt(String key){

        return Integer.parseInt(getString(key));
    }
}
